//
//  TextImageCell.m
//  BeanTrip
//
//  Created by dlios on 15-7-3.
//  Copyright (c) 2015年 PandaGroup. All rights reserved.
//

#import "TextImageCell.h"
#define WIDTH ([UIScreen mainScreen].bounds.size.width/375)
#define HEIGH ([UIScreen mainScreen].bounds.size.height/667)

@implementation TextImageCell

- (void)dealloc
{
    [_myBackgroundView release];
    [_localTimeLabel release];
    [_myMainImageView release];
    [_myTextLabel release];
    [_placeLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //背景视图
        self.myBackgroundView = [[UIView alloc]init];
        [self.contentView addSubview:self.myBackgroundView];
        self.myBackgroundView.layer.cornerRadius = 6;
        [_myBackgroundView release];
        //主要图片
        self.myMainImageView = [[UIImageView alloc] init];
        [self.myBackgroundView addSubview:self.myMainImageView];
        [_myMainImageView release];
        //图片下的文字
        self.myTextLabel = [[UILabel alloc] init];
        self.myTextLabel.numberOfLines = 0;
        self.myTextLabel.lineBreakMode = NSLineBreakByWordWrapping;
        //设置字体大小
        self.myTextLabel.font = [UIFont systemFontOfSize:16*HEIGH];
        [self.myBackgroundView addSubview:self.myTextLabel];
        [_myTextLabel release];
        
        //当地时间
        self.localTimeLabel = [[UILabel alloc] init];
        [self.myBackgroundView addSubview:self.localTimeLabel];
        self.localTimeLabel.font = [UIFont systemFontOfSize:14*HEIGH];
        [_localTimeLabel release];
        //地点
        self.placeLabel  = [[UILabel alloc] init];
        [self.myBackgroundView addSubview:self.placeLabel];
        self.placeLabel.font = [UIFont systemFontOfSize:14*HEIGH];
        self.placeLabel.textAlignment = NSTextAlignmentRight;
        [_placeLabel release];
        
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.myBackgroundView.frame = CGRectMake(10*WIDTH, 5*HEIGH, 375*WIDTH - 20*WIDTH, 667*HEIGH - 10*HEIGH);
    
    CGFloat picHeight = 0;
    if (self.myMainImageView.image.size.width == 0) {
        picHeight = 0;
    }else{
    picHeight = (375*WIDTH - 20*WIDTH) * self.myMainImageView.image.size.height / self.myMainImageView.image.size.width;
    
    }
    
    self.myMainImageView.frame = CGRectMake(0, 0, 375*WIDTH - 20*WIDTH , picHeight);
    
    //文字的高度
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16*HEIGH],NSFontAttributeName, nil];
    CGRect rect = [self.myTextLabel.text boundingRectWithSize:CGSizeMake(375*WIDTH - 20*WIDTH, 3000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.myTextLabel.frame = CGRectMake(0, picHeight, 375*WIDTH - 20*WIDTH, rect.size.height);
    
    
    self.localTimeLabel.frame = CGRectMake(10*WIDTH, picHeight + rect.size.height + 10*HEIGH, (375*WIDTH - 30*WIDTH)/2 , 20*HEIGH);
    self.placeLabel.frame = CGRectMake((375*WIDTH - 20*WIDTH) / 2 , picHeight + rect.size.height+ 10*HEIGH, (375*WIDTH - 20*WIDTH)/2 - 10*WIDTH, 20*HEIGH);
    
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
